package com.zzyl.controller.manager;

import com.github.pagehelper.Page;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingPlanPageQueryDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理")
@Slf4j
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 护理计划分页查询
     * @param dto
     * @return
     */
    @ApiOperation("根据名称和状态分页查询")
    @GetMapping("/search")
    public ResponseResult pageBean(NursingPlanPageQueryDto dto){
        PageBean<NursingPlanVo> pageBean = nursingPlanService.pageBean(dto);
        return ResponseResult.success(pageBean);
    }
    /**
     * 添加护理计划
     */
    @ApiOperation("添加护理计划")
    @PostMapping()
    public ResponseResult add(@RequestBody NursingPlanDto dto){
        log.info("添加护理计划:{}",dto);
        nursingPlanService.add(dto);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理计划
     * @param id
     * @return
     */
    @ApiOperation("根据ID查询护理计划")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 修改护理计划
     * @param dto
     * @return
     */
    @ApiOperation("修改护理计划")
    @PutMapping("/{id}")
    public ResponseResult update(@RequestBody NursingPlanDto dto){
        nursingPlanService.update(dto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     * @param id
     * @return
     */
    @ApiOperation("删除护理计划")
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.delete(id);
        return ResponseResult.success();
    }
    /**
     * 启用,禁用护理计划
     */
    @ApiOperation("启用、禁用护理计划")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult startOrStop(@PathVariable Long id,
                                      @PathVariable Integer status){
        nursingPlanService.startOrStop(id,status);
        return ResponseResult.success();
    }
    /**
     * 查询所有护理计划
     */
    @ApiOperation("查询所有护理计划")
    @GetMapping()
    public ResponseResult getAllNP(){
        List<NursingPlanVo> list = nursingPlanService.getAllNP();
        return ResponseResult.success(list);
    }
}
